<?
layout("/inc/layout.html",{title:sysTitle}){
?>
<<style>
<!--
#findUser img{max-height: 30px;}
.tdType td{
text-align:center;
vertical-align:middle;
}
.table>tbody>tr>td{
	vertical-align:middle;
}

-->
</style>
<div id="page-wrapper">
	<!--BEGIN TITLE & BREADCRUMB PAGE-->
	<div id="title-breadcrumb-option-demo" class="page-title-breadcrumb">
		<div class="page-header pull-left">
			<div class="page-title">直播间管理</div>
		</div>
		<ol class="breadcrumb page-breadcrumb pull-left">
			<li><i class="fa fa-home"></i>&nbsp;<a href="main.html">首页</a>&nbsp;&nbsp;<i
				class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
			<li>直播管理&nbsp;&nbsp;<i class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
			<li class="active">直播间管理</li>
		</ol>

		<div class="clearfix"></div>
	</div>
	<!--END TITLE & BREADCRUMB PAGE-->
	<!--BEGIN CONTENT-->
	<div class="page-content">


		<div class="row mbl" >
			<div class="col-lg-6">
				<div class="input-group input-group-sm mbs">
					<span class="input-group-btn">
						<select id="queryParams" data-toggle="dropdown" class="btn btn-danger dropdown-toggle" style="width :100px;">
		                    <option value="LiveTitle">直播间名称</option>
		                    <option value="anchorUsername">主播名</option>
		                    <option value="anchorNumber">主播编号</option>
                    	</select>
                   </span> 
                    	<input id="text" type="text" placeholder="请输入关键词..." class="form-control" /><span
						class="input-group-btn"><button type="button"
							data-toggle="dropdown" class="btn btn-success dropdown-toggle" onclick="demo(1)">搜索</button>
					</span>
				</div>
			</div>
			<div class="col-lg-6">
				<div class="tb-group-actions pull-right">
					<!-- <span >当前已选择<span id="Xuannum">0</span>条记录:</span> 
					<button class="btn btn-sm btn-primary" onclick="delePiLiang()">
						<i class="fa fa-check"></i>&nbsp; 删除多项
					</button>   -->
					<button class="btn btn-sm btn-primary" onclick="addUpdateCategory('0')">新增
					</button>
				</div>
			</div>
		</div>

		<table
			class="table table-hover table-striped table-bordered table-advanced tablesorter mbn">
			<thead>
				<tr>
					<th >序号</th>
					<th >封面图片 </th>
					<th >主播用户名</th>
					<th >主播编号</th>
					<th >直播间名称</th>
					<th >状态</th>
					<th >直播状态</th>
					<th >可操作</th>
				</tr>
			</thead>
			<tbody id="findUser">
			</tbody>
		</table>
		<div id="dataNull" class="panel-body"
				style="height: 90px; line-height: 50px;" align="center">
		</div>
		<div id="page2" style="text-align: center; margin-top: 20px;"></div>
	</div>

	<!--END CONTENT-->
</div>


<?} ?>
<script>
	var curr;
	var id;
	var ye;
	$("#text").keyup(function(){
		if(event.keyCode == 13){
			demo(1);
		}
	});
	$(function() {
		demo(1);
	});
	function getId() {
		return id;
	}
	function getCurr() {
		return ye;
	}
	function demo(curr) {
		$.ajax({
			type : "post",
			data : {
				"page" : curr || 1,
				"queryParams":$("#queryParams").val(),
        		"text":$("#text").val(),
        		"number":15
			},
			url : "getLiveRoomList.do",
			dataType : "json",
			beforeSend : function(XMLHttpRequest) {},
			success : function(data){
				//此处仅仅是为了演示变化的内容
				var str = "";
				$("#findUser").html("");
				if(data[0].count>0){
					$("#dataNull").html("");
				}else{
					$("#dataNull").html("<span class='subtitle' style='font-size: 15px;'>数据为空!</span>");
				}
				for ( var i = 0; i < data[0].data.length; i++) {
					var status='';
					if(data[0].data[i].status == 0){
						status='待审核';
					}else if(data[0].data[i].status == 1){
						status='审核通过';
					}else{
						status='审核不通过';
					}
					var liveStatus='';
					if(data[0].data[i].liveStatus == 0){
						liveStatus='停播中';
					}else if(data[0].data[i].liveStatus == 1){
						liveStatus='直播中';
					}else{
						liveStatus='禁播中';
					}
					
					str += "<tr><td>"
							+ (i + 1)
							+ "</td><td width='7%' align='center'><img src=\""+data[0].data[i].liveCover+"\">"
							+ "</td><td>"
							+ data[0].data[i].anchorUsername
							+ "</td><td>"
							+ data[0].data[i].anchorNumber
							+ "</td><td>"
							+ data[0].data[i].liveTitle
							+ "</td><td>"
							+ status
							+ "</td><td><span>"
							+ liveStatus
							+ "</span></td><td width='25%'>"
							+ "<button type=\"button\" class=\"btn btn-default btn-xs\"onclick=\"addUpdateCategory('"
							+ data[0].data[i].id
							+ "')\">"
							+ "编辑"
							+ "</button>&nbsp;"
							+ "<button type=\"button\" class=\"btn btn-default btn-xs\"  onclick=\"del('"
							+ data[0].data[i].id
							+ "')\">"
							+ "删除"
							+ "</button>&nbsp;" 
							if(data[0].data[i].status!=0){
							}else{
								str += "<button type=\"button\" class=\"btn btn-default btn-xs\"  onclick=\"subject('"
								str += data[0].data[i].id
								str += "','1')\">"
								str += "审核通过"
								str += "</button>&nbsp;" 
								str += "<button type=\"button\" class=\"btn btn-default btn-xs\"  onclick=\"subject('"
								str += data[0].data[i].id
								str += "','2')\">"
								str += "审核不通过"
								str += "</button>&nbsp;" 
							}
							if(data[0].data[i].status==1){
								if(data[0].data[i].liveStatus==2){
									str += "<button type=\"button\" class=\"btn btn-default btn-xs\"  onclick=\"banned('"
									str += data[0].data[i].id
									str += "','0')\">"
									str += "恢复直播"
									str += "</button>" 
								}else{
									str += "<button type=\"button\" class=\"btn btn-default btn-xs\"  onclick=\"banned('"
									str += data[0].data[i].id
									str += "','2')\">"
									str += "禁播"
									str += "</button>&nbsp;" 
							}
							}
							
							+ "</td></tr>";
				}
				$("#findUser").append(str);

				laypage({
					cont : document.getElementById('page2'), //容器。值支持id名、原生dom对象，jquery对象,
					pages : data[0].page, //总页数
					skip : true, //是否开启跳页
					skin : 'molv', //加载内置皮肤，也可以直接赋值16进制颜色值，如:#c00
					curr: curr || 1,
					last: data[0].page,
					groups : 6,//连续显示分页数
					jump : function(obj, first) { //触发分页后的回调
						if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
							demo(obj.curr);
							 ye = obj.curr;
			                 curr=obj.curr;
						}
					}
				});
			}
		});
	}
	function addUpdateCategory(categoryid) {
		id = categoryid;
		layer.open({
			type : 2,
			area : [ '820px', '580px' ],
		    scrollbar: false,
		    shadeClose: true,
			fix : false, //不固定
			title : '直播间管理',
			//maxmin : true,  
			skin: 'layui-layer-rim', //加上边框
    	    btn: ['保存 ', '关闭'],
			content : ["zhibo_live_room_add_update.html"],
			yes: function(index,layer){
	                var iframeWin = parent.window[layer.find('iframe')[0]['name']];
	                 iframeWin.Page();
	         },
			cancel : function(index) {
			}
			
		});
	}
	function del(id) {
		if (confirm("是否确认删除！！"))
		{
			$.ajax({
				type : "post",
				url : "deldeteLiveRoom.do",
				data : {
					"id" : id
				},
				dataType : "json",
				success : function(data) {
					if(data == "yes"){
						demo(ye);
						layer.msg('删除成功');
					}else{
						layer.msg('删除失败');
					}
				},
				error : function(data) {
					alert("请求失败");
				}
			});
		}
	}
	//审核
	function subject(id,parameter) {
		if (confirm("是否确认当前审核操作？"))
		{
			$.ajax({
				type : "post",
				url : "subjectLiveRoom.do",
				data : {
					"id" : id,
					"parameter" : parameter
				},
				dataType : "json",
				success : function(data) {
					if(data == "yes"){
						demo(ye);
						layer.msg('操作成功');
					}else{
						layer.msg('操作失败');
					}
				},
				error : function(data) {
					alert("请求失败");
				}
			});
		}
	}
	//禁播/取消禁播
	function banned(id,parameter) {
		if (confirm("是否确认当前操作？"))
		{
			$.ajax({
				type : "post",
				url : "bannedLiveRoom.do",
				data : {
					"id" : id,
					"parameter" : parameter
				},
				dataType : "json",
				success : function(data) {
					if(data == "yes"){
						demo(ye);
						layer.msg('操作成功！');
					}else{
						layer.msg('操作失败！');
					}
				},
				error : function(data) {
					alert("请求失败");
				}
			});
		}
	}
	
</script>